<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
      }
      .rated {
        width: 375px;
        height: 205px;
        border: 1px solid #000;
        margin: 50px auto;
        padding: 12px 15px;
      }
      .title {
        font-size: 14px;
        color: #333;
        margin: 0 0 12px;
      }

      ul {
        height: 150px;
        display: flex;
        overflow: auto;
      }

      li {
        flex-shrink: 0;
        width: 85px;
        margin-right: 10px;
        background-color: lightblue;
      }

      li:last-child {
        margin: 0;
      }

      img {
        width: 85px;
        height: 115px;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <my-rated></my-rated>
    </div>

    <script src="../../Vue.js"></script>
    <script>
      const MyRatedItem = {
        props: {
          item: Object,
        },
        template: `
          <li>
            <img :src="item.imgUrl" alt="" />  
            <p>{{ item.title }}</p>
          </li>
        `,
      };

      const MyRated = {
        data() {
          return {
            ratedList: [],
          };
        },
        template: `
          <div class="rated">
            <p class="title">最受好评电影</p>
            <ul>
              <my-rated-item 
                v-for="item in ratedList"
                :key="item._id"
                :item="item"
              ></my-rated-item>
            </ul>
          </div>
        `,
        components: {
          MyRatedItem,
        },
        mounted() {
          // fetch是一个h5自带的数据请求方式
          // 自带封装了promise的
          fetch("http://www.pudge.wang:3080/api/rated/list")
            .then((response) => response.json())
            .then((res) => {
              if (res.status === 0) {
                this.ratedList = res.result;
              }
            });
        },
      };

      new Vue({
        el: "#app",
        data: {},
        components: {
          MyRated,
        },
      });
    </script>
  </body>
</html>
